﻿package com.sonishpere 
{
	import com.saint.utils.Logger;
	import com.sonishpere.events.CountryButtonClickEvent;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author kembera
	 */
	public class InfoButton extends MovieClip
	{
		private var fizzler:Fizzler;
		private var _isActive:Boolean = false;
		private var rollOverAlpha:Number = 1.0;
		private var rollOutAlpha:Number = 1.0;
		private var inactiveAlpha:Number = 0.7;
		
		
		
		public function InfoButton() 
		{
			Logger.info("InfoButton.InfoButton");
		}
		
		public function init(active:Boolean = false) 
		{
			Logger.info("InfoButton.init -  active: " + active);			
			
			_isActive = active;						
			
			
			
			if (_isActive)
			{
				buttonMode = true;
				addEventListener(MouseEvent.ROLL_OVER, onMouseRollOver);
				addEventListener(MouseEvent.ROLL_OUT, onMouseRollOut);
				addEventListener(MouseEvent.CLICK, onMouseClick);
				/* draw Hit area */
				this.graphics.beginFill(0x000000, 0);
				this.graphics.drawRect(0, 0, width, height);
				this.graphics.endFill();			
				/* create the thing to control th rollovers */
				fizzler = new Fizzler(this.content);
				
				content.alpha = rollOutAlpha;
			
			}else {
				content.alpha = inactiveAlpha;
			}
			
			content.gotoAndStop("off");				
			
		}
			
		
		private function onMouseClick(e:MouseEvent):void 
		{
			Logger.debug("InfoButton.onMouseClick")
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK));
		}
		
		private function onMouseRollOut(e:MouseEvent):void 
		{
			content.alpha = rollOutAlpha;
			content.gotoAndStop("off");
		}
		
		private function onMouseRollOver(e:MouseEvent):void 
		{
			content.alpha = rollOverAlpha;
			content.gotoAndStop("on");		
			fizzler.startFizzle();	
		}
		
		public function get isActive():Boolean { return _isActive; }		
		public function set isActive(value:Boolean):void 
		{
			_isActive = value;
		}
		
		
		
	}
	
}